<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
  <script>
      //下面的例子使用get拦截，实现数组读取负数的索引。
      function createArray(...elements) {
          let handler = {
              get(target, propKey, receiver) {
                  let index = Number(propKey);
                  if (index < 0) {
                      propKey = String(target.length + index);
                  }
                  return Reflect.get(target, propKey, receiver);
              }
          };

          let target = [];
          target.push(...elements);
          return new Proxy(target, handler);
      }

      let arr = createArray('a', 'b', 'c');
      arr[-1] // c
  </script>
</body>
</html>